package com.xyxeshang.es.music.backend.controller;

import com.xyxeshang.es.music.backend.annotation.JwtCheck;
import com.xyxeshang.es.music.backend.entity.Listen;
import com.xyxeshang.es.music.backend.entity.Song;
import com.xyxeshang.es.music.backend.entity.SongComment;
import com.xyxeshang.es.music.backend.entity.SongLike;
import com.xyxeshang.es.music.backend.service.SongService;
import com.xyxeshang.es.music.backend.util.ResultUtil;
import org.apache.ibatis.jdbc.Null;
import org.springframework.web.bind.annotation.CrossOrigin;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @author xyx-Eshang
 */
@CrossOrigin
@RestController
@RequestMapping("/song")
public class SongController {

	@Resource
	SongService service;

	/**
	 * 搜索歌曲
	 *
	 * @param key
	 * @param offset
	 * @return
	 */
	@JwtCheck
	@GetMapping("/searchSong")
	public ResultUtil<List<Song>> searchSong(String key, Integer offset) {
		return service.searchSong(key, offset);
	}

	/**
	 * 根据歌曲id和类型获取歌曲信息
	 *
	 * @param songId
	 * @param type
	 * @return
	 */
	@JwtCheck
	@GetMapping("/getSong")
	public ResultUtil<Song> getSong(String songId, String type) {
		return service.getSong(songId, type);
	}

	/**
	 * 播放歌曲
	 *
	 * @param request
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/playSong")
	public ResultUtil<String> playSong(HttpServletRequest request, String songId) {
		return service.playSong(request, songId);
	}

	/**
	 * 获取榜单歌曲
	 *
	 * @param type
	 * @param count
	 * @return
	 */
	@JwtCheck
	@GetMapping("/getBillboard")
	public ResultUtil<List<Song>> getBillboard(String type, Integer count) {
		return service.getBillboard(type, count);
	}

	/**
	 * 新增评论
	 *
	 * @param request
	 * @param songCommentContent
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/addComment")
	public ResultUtil<Integer> addComment(HttpServletRequest request, String songCommentContent, String songId) {
		return service.addComment(request, songCommentContent, songId);
	}

	/**
	 * 删除评论
	 *
	 * @param songCommentId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/deleteComment")
	public ResultUtil<Null> deleteComment(Integer songCommentId) {
		return service.deleteComment(songCommentId);
	}

	/**
	 * 根据歌曲id，查询我的评论
	 *
	 * @param request
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/listMyComment")
	public ResultUtil<List<SongComment>> listMyComment(HttpServletRequest request, String songId) {
		return service.listMyComment(request, songId);
	}

	/**
	 * 根据歌曲id查询所有评论
	 *
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/listComment")
	public ResultUtil<List<SongComment>> listComment(String songId) {
		return service.listComment(songId);
	}

	/**
	 * 点赞
	 *
	 * @param request
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/addLike")
	public ResultUtil<Integer> addLike(HttpServletRequest request, String songId) {
		return service.addLike(request, songId);
	}

	/**
	 * 删除点赞记录
	 *
	 * @param songLikeId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/deleteLike")
	public ResultUtil<Null> deleteLike(Integer songLikeId) {
		return service.deleteLike(songLikeId);
	}

	/**
	 * 根据歌曲id，查询我的点赞记录
	 *
	 * @param request
	 * @param songId
	 * @return
	 */
	@JwtCheck
	@GetMapping("/getMySongLike")
	public ResultUtil<SongLike> getMySongLike(HttpServletRequest request, String songId) {
		return service.getMySongLike(request, songId);
	}

	/**
	 * 查询我点赞的歌曲
	 *
	 * @param request
	 * @return
	 */
	@JwtCheck
	@GetMapping("/listMyLikeSong")
	public ResultUtil<List<Song>> listMyLikeSong(HttpServletRequest request) {
		return service.listMyLikeSong(request);
	}

	/**
	 * 查询我的听歌记录
	 *
	 * @param request
	 * @return
	 */
	@JwtCheck
	@GetMapping("/listMyListen")
	public ResultUtil<List<Listen>> listMyListen(HttpServletRequest request) {
		return service.listMyListen(request);
	}
}
